home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / Tools & Goodies / IntlTest / Sources / Commands.h < prev    next >
Encoding:
Text File  |  1996-09-12  |  6.9 KB  |  242 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Commands.h
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef COMMANDS_H
  11. #define COMMANDS_H
  12.  
  13. // ----- Framework Includes -----
  14.  
  15. #ifndef FWCLPCMD_H
  16. #include "FWClpCmd.h"
  17. #endif
  18.  
  19. #ifndef FWDRCMD_H
  20. #include "FWDrCmd.h"
  21. #endif
  22.  
  23. //========================================================================================
  24. // Forward Declarations
  25. //========================================================================================
  26.  
  27. class CIntlTestSelection;
  28. class CIntlTestSelectedContent;
  29. class CMyEditView;
  30. class FW_CEditView;
  31. class FW_CString;
  32.  
  33. //========================================================================================
  34. //    class CIntlTestDropCommand
  35. //========================================================================================
  36.  
  37. class CIntlTestDropCommand : public FW_CDropCommand
  38. {
  39.   public:
  40.     FW_DECLARE_AUTO(CIntlTestDropCommand)
  41.  
  42.     CIntlTestDropCommand(Environment* ev,
  43.                          FW_CFrame* frame,
  44.                          FW_CEditView* dropView,
  45.                          CIntlTestSelection* selection,
  46.                          ODDragItemIterator* dropInfo, 
  47.                          ODFacet* odFacet,
  48.                          const FW_CPoint& dropPoint);
  49.  
  50.     virtual ~CIntlTestDropCommand();
  51.  
  52.   public:
  53.     virtual void        UndoIt(Environment* ev);
  54.     virtual void        RedoIt(Environment* ev);
  55.     virtual void        SaveUndoState(Environment* ev);
  56.     virtual void         SaveRedoState(Environment* ev);
  57.  
  58.   private:
  59.     void                SwapText(Environment* ev, 
  60.                                  FW_ByteCount bytesToRemove, 
  61.                                  const FW_CString& textToRestore);
  62.  
  63. //----- Data Members -----
  64.   private:
  65.     FW_CEditView*                fDropEditView;
  66.     CIntlTestSelection*            fTextSelection;
  67.     // Saved data for undo/redo
  68.     FW_CString                    fDroppedText;
  69.     FW_CString                    fSavedText;    
  70.     short                        fSavedOffset;
  71. };
  72.  
  73. //========================================================================================
  74. //    class CIntlTestEditCommand
  75. //========================================================================================
  76. class CIntlTestEditCommand : public FW_CClipboardCommand
  77. {
  78.   public:
  79.     FW_DECLARE_AUTO(CIntlTestEditCommand)
  80.  
  81.     CIntlTestEditCommand(Environment* ev, 
  82.                          ODCommandID commandID,
  83.                          FW_CFrame* frame, 
  84.                          CIntlTestSelection* selection,
  85.                          FW_CEditView* editView,
  86.                          FW_Boolean canUndo);
  87.  
  88.     virtual ~ CIntlTestEditCommand();
  89.  
  90.     // ----- FW_CCommand overrides -----
  91.     virtual void         UndoIt(Environment* ev);
  92.     virtual void         RedoIt(Environment* ev);
  93.     virtual void         SaveUndoState(Environment* ev);
  94.     virtual void         SaveRedoState(Environment* ev);
  95.  
  96.     // ----- FW_CClipboardCommand overrides -----
  97.     virtual void        PreCommand(Environment* ev);
  98.  
  99.   private:
  100.     void RemoveText(Environment* ev);
  101.     void RestoreText(Environment* ev);
  102.     void RemoveAndRestoreText(Environment* ev, FW_ByteCount bytesToRemove, const FW_CString& textToRestore);
  103.  
  104.   private:
  105.     CIntlTestSelection*            fTextSelection;
  106.     FW_CEditView*                fEditView;
  107.     //--- Saved data for undo/redo
  108.     FW_CString                    fPastedText;
  109.     FW_CString                    fSavedText;        // original text (Paste command)
  110.     short                        fStartOffset;
  111.     short                        fEndOffset;
  112. };
  113.  
  114. //========================================================================================
  115. //    class CTypingCommand
  116. //========================================================================================
  117.  
  118. class CTypingCommand : public FW_CCommand
  119. {
  120.   public:
  121.     FW_DECLARE_AUTO(CTypingCommand)
  122.  
  123.     CTypingCommand(Environment* ev, 
  124.                    ODCommandID commandID,
  125.                    FW_CFrame* frame, 
  126.                    FW_CEditView* editView,
  127.                    FW_Boolean canUndo,
  128.                    char firstChar);
  129.  
  130.     virtual ~ CTypingCommand();
  131.  
  132.     // ----- FW_CCommand overrides -----
  133.     virtual void     DoIt(Environment* ev);
  134.     virtual void     UndoIt(Environment* ev);
  135.     virtual void     RedoIt(Environment* ev);
  136.     virtual void     SaveUndoState(Environment* ev);
  137.     virtual void     SaveRedoState(Environment* ev);
  138.  
  139.     // --- handling character input
  140.     void        AddCharacter(Environment* ev, char ch);
  141.     void        Backspace(Environment* ev, char bsChar);
  142.     void        CompleteTyping(Environment* ev);
  143.     FW_Boolean    IsNotCompleted();
  144.  
  145.   protected:
  146.     FW_CEditView*                fEditView;
  147.     FW_Boolean                    fCompleted;        // F: add further keystrokes to cmd
  148.   private:
  149.     char                        fFirstChar;        // first character typed
  150.   protected:
  151.     //--- Saved data for undo/redo
  152.     FW_CString                    fTypedText;        // newly-typed string
  153.     FW_CString                    fSavedText;        // original string (typed over)
  154.     short                        fStartOffset;
  155.     short                        fEndOffset;
  156. };
  157.  
  158. //-----------------------------------------------------------------------------------------
  159. inline FW_Boolean CTypingCommand::IsNotCompleted()
  160. {
  161.     return !fCompleted;
  162. }
  163.  
  164. //========================================================================================
  165. struct CTSMInput
  166. {
  167.     char            fByte;            // either a single-byte char, like BS or CR
  168.     char*            fChars;            // or confirmed chars from TSM
  169.     FW_ByteCount    fByteCount;        // 0: use fByte; >0: use fChars
  170.  
  171.     CTSMInput(char ch)            { fByte = ch; fChars = NULL; fByteCount = 0; }
  172.     CTSMInput(char* chars, FW_ByteCount count)    
  173.                                 { fByte = 0; fChars = chars; fByteCount = count; }
  174.     FW_Boolean IsMultiByte()    { return fByteCount != 0; }
  175. };
  176.  
  177. //========================================================================================
  178. //    class CTSMTypingCommand
  179. //========================================================================================
  180.  
  181. class CTSMTypingCommand : public CTypingCommand
  182. {
  183.   public:
  184.     FW_DECLARE_AUTO(CTSMTypingCommand)
  185.  
  186.     CTSMTypingCommand(Environment* ev, 
  187.                       ODCommandID commandID,
  188.                       FW_CFrame* frame, 
  189.                       FW_CEditView* editView,
  190.                       CTSMInput* firstInput);
  191.  
  192.     virtual ~ CTSMTypingCommand();
  193.  
  194.     // ----- FW_CCommand overrides -----
  195.     virtual void     DoIt(Environment* ev);
  196.  
  197.   public:
  198.     // --- handling character input
  199.     void            AddInput(Environment* ev, CTSMInput* input);
  200.     void            Backspace(Environment* ev);
  201.     FW_Boolean        IsCompleted();
  202.  
  203.   private:
  204.     CTSMInput*        fFirstInput;        // first characters input
  205. };
  206.  
  207. //-----------------------------------------------------------------------------------------
  208. inline FW_Boolean CTSMTypingCommand::IsCompleted()
  209. {
  210.     return fCompleted;
  211. }
  212.  
  213. //========================================================================================
  214. //    class CFontCommand - change font or font size (undoable)
  215. //========================================================================================
  216. class CFontCommand : public FW_CCommand
  217. {
  218.   public:
  219.     FW_DECLARE_AUTO(CFontCommand)
  220.  
  221.     CFontCommand(Environment* ev, 
  222.                  ODCommandID commandID,
  223.                  FW_CFrame* frame, 
  224.                  CMyEditView* editView);
  225.  
  226.     virtual ~ CFontCommand();
  227.  
  228.     // ----- FW_CCommand overrides -----
  229.     virtual void         DoIt(Environment* ev);
  230.     virtual void         UndoIt(Environment* ev);
  231.     virtual void         RedoIt(Environment* ev);
  232.  
  233.   private:
  234.     FW_CFont        fOldFont;            // for Undo
  235.     ODCommandID        fOldFontCommand;    // for Undo
  236.     FW_CFont        fNewFont;            // for Redo
  237.     CMyEditView*    fEditView;
  238.     FW_Boolean        fNameChange;        // F: font size change
  239. };
  240.  
  241. #endif
  242.